package com.qf.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.qf.Dao.RegisterDao;
import com.qf.Dao.impl.RegisterDaoImpl;
import com.qf.entity.Register;
import com.qf.service.RegisterService;
import com.qf.utils.PageUtils;

import java.util.List;

/**
 * @author chengqiang
 * @Create 2023-12-05-16:28
 * Description:
 */
public class RegisterServiceImpl implements RegisterService {

    private RegisterDao registerDao = new RegisterDaoImpl();
    @Override
    public PageUtils<Register> selectByPage(String rid, String dname, String startTime, String endTime, String currentPageNoStr, String pageSizeStr) {

        Integer currentPageNo;
        if(StringUtils.isEmpty(currentPageNoStr)){
            currentPageNo = 1;
        }else {
            currentPageNo = Integer.parseInt(currentPageNoStr);
        }
        Integer pageSize;

        if(StringUtils.isEmpty(pageSizeStr)){
            pageSize = 3;
        }else {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        //  当前页
        Integer totalPageCount = registerDao.selectByRegisterCount(rid, dname, startTime, endTime);
        //  总页数
        Integer totalPageSize = totalPageCount % pageSize ==0 ? totalPageCount / pageSize : totalPageCount / pageSize+1;
        // Register对象集合
        List<Register> registerList = registerDao.seletByPageRegister(rid, dname, startTime, endTime,currentPageNo,pageSize);


        PageUtils<Register> pageUtils = new PageUtils<>();

        pageUtils.setCurrentPageNo(currentPageNo);
        pageUtils.setPageSize(pageSize);
        pageUtils.setTotalPageCount(totalPageCount);
        pageUtils.setTotalPageSize(totalPageSize);
        pageUtils.setDataList(registerList);

        return pageUtils;
    }
}
